package com.example.mqspring.rabiitmqbasicleverone.rabbitmqDirectRoutkey;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;

public class Consumer extends DefaultConsumer {

    /**
     * @param channel the channel to which this consumer is attached
     */
    public Consumer(Channel channel) {
        super(channel);
    }

    public Channel declareConsumer(String queue,Channel channel, String MyExchange, String routingkey) throws Exception {
        channel.exchangeDeclare(MyExchange,"direct",false,false,null);
        channel.queueBind(queue,MyExchange,routingkey);
        return channel;
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        System.out.println(new String(body));
    }
}
